package com.quan.mall.service.impl;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.commons.core.biz.support.MyBaseServiceImpl;
import com.quan.commons.core.utils.PageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.quan.mall.commons.vo.UmsMemberDistributionApplyVo;
import com.quan.mall.entity.UmsMemberDistributionApply;
import com.quan.mall.mapper.UmsMemberDistributionApplyMapper;
import com.quan.mall.service.UmsMemberDistributionApplyService;


@Slf4j
@Service
public class UmsMemberDistributionApplyServiceImpl extends MyBaseServiceImpl<UmsMemberDistributionApplyMapper, UmsMemberDistributionApply> implements UmsMemberDistributionApplyService {

    @Autowired
	private UmsMemberDistributionApplyMapper mapper;

	@Override
    public List<UmsMemberDistributionApplyVo> queryList(PageUtils pageUtils, UmsMemberDistributionApplyVo vo) {
        QueryWrapper<UmsMemberDistributionApply> queryWrapper = new QueryWrapper<UmsMemberDistributionApply>(vo);

        List<UmsMemberDistributionApply> list = super.list(pageUtils, queryWrapper);
        List<UmsMemberDistributionApplyVo> collect = list.stream().map(item -> {
            UmsMemberDistributionApplyVo bean = new UmsMemberDistributionApplyVo();
            BeanUtils.copyProperties(item, bean);
            return bean;
        }).collect(Collectors.toList());

        return collect;
    }

    @Override
    public PageUtils queryPage(PageUtils pageUtils, UmsMemberDistributionApplyVo vo) {
        QueryWrapper<UmsMemberDistributionApply> queryWrapper = new QueryWrapper<UmsMemberDistributionApply>(vo);

        if(StringUtils.isNotBlank(vo.getKeyword())) {
            queryWrapper.and(w -> {
                w.like("name", vo.getKeyword());
            });
        }

        final IPage<UmsMemberDistributionApply> page = super.selectPage(pageUtils, queryWrapper);

        PageUtils ps = new PageUtils(page);

        final List<UmsMemberDistributionApply> records = page.getRecords();

        final List<UmsMemberDistributionApply> collect = records.stream().map((item) -> {
            UmsMemberDistributionApplyVo bean = new UmsMemberDistributionApplyVo();
            BeanUtils.copyProperties(item, bean);
            return bean;
        }).collect(Collectors.toList());

        ps.setRecords(collect);
        return ps;
    }
}